package logic

import (
	"context"
	"house-hub/models"

	"house-hub/houserpc/houserpc"
	"house-hub/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品添加
func (l *GoodsAddLogic) GoodsAdd(in *houserpc.GoodsAddRequest) (*houserpc.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line

	goods := models.Goods{
		Title:  in.Title,
		UserId: int(in.UserId),
		Price:  float64(in.Price),
	}

	if err := goods.GoodsAdd(models.DB); err != nil {
		return nil, err
	}

	return &houserpc.GoodsAddResponse{
		GoodsId: int64(goods.ID),
	}, nil
}
